package Other;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo4 {
    public static void main(String[] args) {
        // 假设我们有个 List，里面放到好多数字，要求找出满足 偶数 && n > 10 && n < 20 && n 能被 3 整除
        List<Integer> list = createList();
        // 不使用 stream 流的方法
        List<Integer> ans1 = new ArrayList<>();
        for (int e : list) {
            if (e % 2 == 0) {
                ans1.add(e);
            }
        }

        List<Integer> ans2 = new ArrayList<>();
        for (int e : ans1) {
            if (e > 10) {
                ans2.add(e);
            }
        }

        // 使用 stream 流
        Stream<Integer> stream1 = list.stream();
        Stream<Integer> stream2 = stream1.filter(e -> e % 2 == 0);
        Stream<Integer> stream3 = stream2.filter(e -> e > 10);
        Stream<Integer> stream4 = stream3.filter(e -> e < 20);
        Stream<Integer> stream5 = stream4.filter(e -> e % 3 == 0);
        List<Integer> ans = stream5.collect(Collectors.toList());

        List<Integer> ans__ = list.stream()
                .filter(e -> e % 2 == 0)
                .filter(e -> e > 10)
                .filter(e -> e < 20)
                .filter(e -> e % 3 == 0)
                .collect(Collectors.toList());
    }

    private static List<Integer> createList() {
        return null;
    }
}
